package com.android.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SMSActivity extends Activity {
	final static String TAG ="SMSActivity";
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sms);
		
		this.onStartButtomClick();
	}

		
	/**
	 * Acci�n para el boton start
	 * 
	 * Lanza el sms que inicializa el Receiver
	 */
	public void onStartButtomClick() {
		Button start = (Button) findViewById(R.id.btn_sms);
		
		start.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Log.e(TAG, "boton pulsado");
				EditText eSMS_phone = (EditText) findViewById(R.id.SMS_phone);
				String SMS_phone = eSMS_phone.getText().toString();
				String SMS_msg = getResources().getString(R.string.SMS_msg);
				Log.e(TAG, "Valores : "+SMS_phone.length()+ " " + SMS_phone+ " SMS_msg: "+ SMS_msg);
				if (SMS_phone.length() > 0 && SMS_msg.length()>0) {
					Log.e(TAG, "Lanzando SMS"+SMS_phone.length()+ " " + SMS_phone);
				SmsManager sms = SmsManager.getDefault();
		        sms.sendTextMessage(SMS_phone, null, SMS_msg, null /*pi*/, null);
				startActivity(new Intent(SMSActivity.this, SenderActivity.class));
				}
                else{
                	Log.e(TAG, "Lanzando Toast");
                    Toast.makeText(getBaseContext(), 
                        getResources().getString(R.string.mobile_telf_num), 
                        Toast.LENGTH_SHORT).show();
                }
            }

				
			
		});
	}
}